﻿using System;
using System.Linq;
using InseSoft.Infraestructure;
using InseSoft.ViewModels;
using InseSoft.Views;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Ninject;

namespace InseSoft.Tests.Unit.ViewModels
{
    [TestClass]
    public class WindowLauncherTest
    {
        [TestMethod]
        public void Constructor_AllWindowsConfigured()
        {
            var instance = new WindowLauncher();
            var windows = Enum.GetValues(typeof(AppView)).Cast<AppView>();
            
            foreach(var window in windows)
                Assert.IsTrue(instance.Configuration.ContainsKey(window));
        }

        [TestMethod]
        public void Show_ViewSetup()
        {
            const AppView appWindow = AppView.Clientes;

            var instance = new WindowLauncher();
            var viewMock = new Mock<IWindow>();
            var viewModelMock = new Mock<IEntityViewModel>();
            var kernelMock = new Mock<IKernel>();
            var viewFunc = new Func<IWindow>(() => viewMock.Object);
            var viewModelFunc = new Func<IEntityViewModel>(() => viewModelMock.Object);
            var viewViewModel = new ViewViewModel(viewFunc, viewModelFunc);
            DIFactory.Kernel = kernelMock.Object;
            instance.Configuration[appWindow] = viewViewModel;

            instance.Show(appWindow);

            kernelMock.Verify(k => k.Inject(viewModelMock.Object), Times.Once());
            viewModelMock.Verify(vm => vm.Initialize(), Times.Once());
            viewModelMock.Verify(vm => vm.Dispose(), Times.Once());
            viewMock.Verify(v => v.ShowDialog(), Times.Once());
        }

        [TestMethod]
        public void Configuration()
        {

        }
    }
}
